package ${adminPackage}.controller.${tablePrefix};

import cn.dev33.satoken.annotation.SaCheckPermission;
import ${bizPackage}.service.${tablePrefix}.${entityName}Service;
import ${commonPackage}.R;
import ${commonPackage}.dto.${tablePrefix}.${entityName}AddDTO;
import ${commonPackage}.dto.${tablePrefix}.${entityName}ModifyDTO;
import ${commonPackage}.dto.${tablePrefix}.${entityName}PageDTO;
import ${commonPackage}.vo.${tablePrefix}.${entityName}DetailVO;
import ${commonPackage}.vo.${tablePrefix}.${entityName}PageVO;
import com.mybatisflex.core.paginate.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * ${tableComment}
 *
 * @author ${username}
 * @date ${createTime}
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/${tablePrefix}/${mappingBase}")
public class ${entityName}Controller {

	private final ${entityName}Service ${entityNameLowerFirst}Service;

	/**
	 * 添加
	 *
	 * @param ${entityNameLowerFirst}AddDTO 新增dto
	 * @return {@link R }<{@link ? }>
	 */
	@SaCheckPermission("${basePermission}:add")
	@PostMapping
	public R<?> addOne(@RequestBody @Validated ${entityName}AddDTO ${entityNameLowerFirst}AddDTO) {
		${entityNameLowerFirst}Service.addOne(${entityNameLowerFirst}AddDTO);
		return R.ok();
	}

	/**
	 * 删除
	 *
	 * @param id 主键
	 * @return {@link R }<{@link ? }>
	 */
	@SaCheckPermission("${basePermission}:delete")
	@DeleteMapping("/{id}")
	public R<?> deleteById(@PathVariable Long id) {
		${entityNameLowerFirst}Service.deleteById(id);
		return R.ok();
	}

	/**
	 * 修改
	 *
	 * @param id 主键
	 * @param ${entityNameLowerFirst}ModifyDTO 更新dto
	 * @return {@link R }<{@link ? }>
	 */
	@SaCheckPermission("${basePermission}:modify")
	@PutMapping("/{id}")
	public R<?> modifyById(@PathVariable Long id,
	                       @RequestBody @Validated ${entityName}ModifyDTO ${entityNameLowerFirst}ModifyDTO) {
		${entityNameLowerFirst}Service.modifyById(id, ${entityNameLowerFirst}ModifyDTO);
		return R.ok();
	}

	/**
	 * 详情
	 *
	 * @param id 主键
	 * @return {@link R }<{@link ${entityName}DetailVO }>
	 */
	@SaCheckPermission("${basePermission}:detail")
	@GetMapping("/detail/{id}")
	public R<${entityName}DetailVO> detailById(@PathVariable Long id) {
		${entityName}DetailVO ${entityNameLowerFirst}DetailVO = ${entityNameLowerFirst}Service.detailById(id);
		return R.ok(${entityNameLowerFirst}DetailVO);
	}

	/**
	 * 分页查询
	 * @param page            				 页面
	 * @param size            				 大小
	 * @param ${entityNameLowerFirst}PageDTO 分页查询条件
	 * @return {@link R }<{@link Page<${entityName}PageVO> }>
	 */
	@SaCheckPermission("${basePermission}:list")
	@GetMapping("/page/{page}/{size}")
	public R<Page<${entityName}PageVO>> queryPage(@PathVariable Long page, @PathVariable Long size, ${entityName}PageDTO ${entityNameLowerFirst}PageDTO) {
		Page<${entityName}PageVO> pageData = ${entityNameLowerFirst}Service.queryPage(page, size, ${entityNameLowerFirst}PageDTO);
		return R.ok(pageData);
	}
}
